A fast and flexible LRU map
This repository contains a fast and flexible LRU map.
- Blazingly fast. Up to twice as fast as the
lru
crate, and with less memory overhead. - Can be also used as an ordered map, with roughly the same performance as
indexmap
, but with added support for O(1) removals without changing the element order (whereindexmap
only supports O(n) non-perturbing removals). - Customizable. Out-of-box can be limited by length or by memory usage, but supports custom limiters which can be made to limit the map by whatever you want.
- Tested, miri-clean, clippy-clean and fuzzed.
- Supports
no_std
.
Examples
use ;
let mut map = new;
// Insert three elements.
map.insert;
map.insert;
map.insert;
assert_eq!;
// They're ordered according to which one was inserted last.
let mut iter = map.iter;
assert_eq!;
assert_eq!;
assert_eq!;
// Access the least recently inserted one.
assert_eq!;
// Now the order's changed.
// The element we've accessed was moved to the front.
let mut iter = map.iter;
assert_eq!;
assert_eq!;
assert_eq!;
// Insert a fourth element.
// This will automatically pop the least recently accessed one.
map.insert;
// Still the same number of elements.
assert_eq!;
// And this is the one which was removed.
assert!;
// And here's the new order.
let mut iter = map.iter;
assert_eq!;
assert_eq!;
assert_eq!;
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.